<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>JNI学习笔记 | 江流</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/favicon.ico">
    <script>
	  var _hmt = _hmt || [];
	  (function() {
	    var hm = document.createElement("script");
		hm.src = "https://hm.baidu.com/hm.js?d53065bd59576478808301d9b305d57a";
	    var s = document.getElementsByTagName("script")[0]; 
	    s.parentNode.insertBefore(hm, s);
	  })();
	  </script>        
	  </script>
    <meta name="description" content="我的知识存储空间，不大不小刚刚好！">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/assets/css/0.styles.f7444686.css" as="style"><link rel="preload" href="/assets/js/app.371ed010.js" as="script"><link rel="preload" href="/assets/js/3.fe7e7b6d.js" as="script"><link rel="preload" href="/assets/js/1.adb5634c.js" as="script"><link rel="preload" href="/assets/js/36.470d3b70.js" as="script"><link rel="prefetch" href="/assets/js/10.1f1951c3.js"><link rel="prefetch" href="/assets/js/100.61abc83e.js"><link rel="prefetch" href="/assets/js/101.36b1a9cd.js"><link rel="prefetch" href="/assets/js/102.ab6aaef1.js"><link rel="prefetch" href="/assets/js/103.56b65027.js"><link rel="prefetch" href="/assets/js/104.10a9920d.js"><link rel="prefetch" href="/assets/js/105.2af1fce1.js"><link rel="prefetch" href="/assets/js/106.89d909fa.js"><link rel="prefetch" href="/assets/js/107.8a051ba9.js"><link rel="prefetch" href="/assets/js/108.8d32e2bb.js"><link rel="prefetch" href="/assets/js/109.98a9c733.js"><link rel="prefetch" href="/assets/js/11.4f1a38c2.js"><link rel="prefetch" href="/assets/js/110.cb2819bf.js"><link rel="prefetch" href="/assets/js/111.3763e438.js"><link rel="prefetch" href="/assets/js/112.437502fc.js"><link rel="prefetch" href="/assets/js/113.c84b80e9.js"><link rel="prefetch" href="/assets/js/114.e8265ab7.js"><link rel="prefetch" href="/assets/js/115.5950f39b.js"><link rel="prefetch" href="/assets/js/116.7082589d.js"><link rel="prefetch" href="/assets/js/117.9ab33002.js"><link rel="prefetch" href="/assets/js/118.b03051ef.js"><link rel="prefetch" href="/assets/js/119.31fe4216.js"><link rel="prefetch" href="/assets/js/12.397d3f87.js"><link rel="prefetch" href="/assets/js/120.4d52fd08.js"><link rel="prefetch" href="/assets/js/121.024a68dc.js"><link rel="prefetch" href="/assets/js/122.75cd9e9a.js"><link rel="prefetch" href="/assets/js/123.3060f162.js"><link rel="prefetch" href="/assets/js/124.b65e3f9b.js"><link rel="prefetch" href="/assets/js/125.87d06856.js"><link rel="prefetch" href="/assets/js/126.23d0d6ec.js"><link rel="prefetch" href="/assets/js/127.1ff7063e.js"><link rel="prefetch" href="/assets/js/128.e7a78683.js"><link rel="prefetch" href="/assets/js/129.3a378a54.js"><link rel="prefetch" href="/assets/js/13.d1346059.js"><link rel="prefetch" href="/assets/js/130.3820ccc0.js"><link rel="prefetch" href="/assets/js/14.961feb61.js"><link rel="prefetch" href="/assets/js/15.61355499.js"><link rel="prefetch" href="/assets/js/16.6759c278.js"><link rel="prefetch" href="/assets/js/17.39315298.js"><link rel="prefetch" href="/assets/js/18.9995ddc3.js"><link rel="prefetch" href="/assets/js/19.e7007f1f.js"><link rel="prefetch" href="/assets/js/20.8284a0ff.js"><link rel="prefetch" href="/assets/js/21.42efcf40.js"><link rel="prefetch" href="/assets/js/22.ce83188a.js"><link rel="prefetch" href="/assets/js/23.125b374b.js"><link rel="prefetch" href="/assets/js/24.9a24b2f6.js"><link rel="prefetch" href="/assets/js/25.61d7e926.js"><link rel="prefetch" href="/assets/js/26.4c271fce.js"><link rel="prefetch" href="/assets/js/27.08314644.js"><link rel="prefetch" href="/assets/js/28.44a30857.js"><link rel="prefetch" href="/assets/js/29.4b86327a.js"><link rel="prefetch" href="/assets/js/30.284e1438.js"><link rel="prefetch" href="/assets/js/31.c7fb218e.js"><link rel="prefetch" href="/assets/js/32.9591edea.js"><link rel="prefetch" href="/assets/js/33.52d0ee09.js"><link rel="prefetch" href="/assets/js/34.24dce9bc.js"><link rel="prefetch" href="/assets/js/35.e9e59a19.js"><link rel="prefetch" href="/assets/js/37.f43d4d57.js"><link rel="prefetch" href="/assets/js/38.bb14e7a9.js"><link rel="prefetch" href="/assets/js/39.4238fcd3.js"><link rel="prefetch" href="/assets/js/4.10111819.js"><link rel="prefetch" href="/assets/js/40.eb5830d8.js"><link rel="prefetch" href="/assets/js/41.f2de0dd7.js"><link rel="prefetch" href="/assets/js/42.ee6bc670.js"><link rel="prefetch" href="/assets/js/43.aeb80fc2.js"><link rel="prefetch" href="/assets/js/44.3dcf73d7.js"><link rel="prefetch" href="/assets/js/45.f60dd2b7.js"><link rel="prefetch" href="/assets/js/46.3ffd9a49.js"><link rel="prefetch" href="/assets/js/47.0629cfd8.js"><link rel="prefetch" href="/assets/js/48.4064d363.js"><link rel="prefetch" href="/assets/js/49.e5cd2868.js"><link rel="prefetch" href="/assets/js/5.bbaa5544.js"><link rel="prefetch" href="/assets/js/50.e1524d44.js"><link rel="prefetch" href="/assets/js/51.ef5d60b4.js"><link rel="prefetch" href="/assets/js/52.9e15bbc1.js"><link rel="prefetch" href="/assets/js/53.9e53a9b3.js"><link rel="prefetch" href="/assets/js/54.bda58726.js"><link rel="prefetch" href="/assets/js/55.cdc29215.js"><link rel="prefetch" href="/assets/js/56.3f0607d3.js"><link rel="prefetch" href="/assets/js/57.b45ba0fb.js"><link rel="prefetch" href="/assets/js/58.12450427.js"><link rel="prefetch" href="/assets/js/59.33096dcc.js"><link rel="prefetch" href="/assets/js/6.8df5fb44.js"><link rel="prefetch" href="/assets/js/60.98645e3a.js"><link rel="prefetch" href="/assets/js/61.413d9151.js"><link rel="prefetch" href="/assets/js/62.cc3b9f5a.js"><link rel="prefetch" href="/assets/js/63.05784f29.js"><link rel="prefetch" href="/assets/js/64.d6d2548e.js"><link rel="prefetch" href="/assets/js/65.dfa3ba68.js"><link rel="prefetch" href="/assets/js/66.bb4f5fde.js"><link rel="prefetch" href="/assets/js/67.2c282a4f.js"><link rel="prefetch" href="/assets/js/68.ce435a87.js"><link rel="prefetch" href="/assets/js/69.e439f6e2.js"><link rel="prefetch" href="/assets/js/7.751d2655.js"><link rel="prefetch" href="/assets/js/70.270cc6b6.js"><link rel="prefetch" href="/assets/js/71.ad1e4a0b.js"><link rel="prefetch" href="/assets/js/72.0adf2b53.js"><link rel="prefetch" href="/assets/js/73.72e019b5.js"><link rel="prefetch" href="/assets/js/74.a4eb5a17.js"><link rel="prefetch" href="/assets/js/75.6412ff6f.js"><link rel="prefetch" href="/assets/js/76.7f462fc1.js"><link rel="prefetch" href="/assets/js/77.16502231.js"><link rel="prefetch" href="/assets/js/78.3082b00c.js"><link rel="prefetch" href="/assets/js/79.4f375500.js"><link rel="prefetch" href="/assets/js/8.6c3fab20.js"><link rel="prefetch" href="/assets/js/80.0f2472d6.js"><link rel="prefetch" href="/assets/js/81.136b6c89.js"><link rel="prefetch" href="/assets/js/82.6f5b7de7.js"><link rel="prefetch" href="/assets/js/83.0eb8579b.js"><link rel="prefetch" href="/assets/js/84.b50a036d.js"><link rel="prefetch" href="/assets/js/85.e7b43c1a.js"><link rel="prefetch" href="/assets/js/86.0cbd7e7b.js"><link rel="prefetch" href="/assets/js/87.647fd8a9.js"><link rel="prefetch" href="/assets/js/88.be268039.js"><link rel="prefetch" href="/assets/js/89.2c0b397f.js"><link rel="prefetch" href="/assets/js/9.ace3bd0d.js"><link rel="prefetch" href="/assets/js/90.fb93a187.js"><link rel="prefetch" href="/assets/js/91.45160178.js"><link rel="prefetch" href="/assets/js/92.4e47d015.js"><link rel="prefetch" href="/assets/js/93.2f9bae72.js"><link rel="prefetch" href="/assets/js/94.c68d9319.js"><link rel="prefetch" href="/assets/js/95.a6932cad.js"><link rel="prefetch" href="/assets/js/96.dea31892.js"><link rel="prefetch" href="/assets/js/97.e8c73484.js"><link rel="prefetch" href="/assets/js/98.bf38dbf7.js"><link rel="prefetch" href="/assets/js/99.edd450af.js">
    <link rel="stylesheet" href="/assets/css/0.styles.f7444686.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container" data-v-6f8f7dda><div data-v-6f8f7dda><div class="password-shadow password-wrapper-out" style="display:none;" data-v-f68096de data-v-6f8f7dda data-v-6f8f7dda><h3 class="title" data-v-f68096de>江流</h3> <p class="description" data-v-f68096de>我的知识存储空间，不大不小刚刚好！</p> <label id="box" class="inputBox" data-v-f68096de><input type="password" value="" data-v-f68096de> <span data-v-f68096de>Konck! Knock!</span> <button data-v-f68096de>OK</button></label> <div class="footer" data-v-f68096de><span data-v-f68096de><i class="iconfont reco-theme" data-v-f68096de></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-f68096de>vuePress-theme-reco</a></span> <span data-v-f68096de><i class="iconfont reco-copyright" data-v-f68096de></i> <a data-v-f68096de><span data-v-f68096de>江流</span>
          
        <span data-v-f68096de>2018 - </span>
        2023
      </a></span></div></div> <div class="hide" data-v-6f8f7dda><header class="navbar" data-v-6f8f7dda><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/logo.png" alt="江流" class="logo"> <span class="site-name">江流</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/复盘/" class="nav-link"><i class="undefined"></i>
  复盘
</a></li><li class="dropdown-item"><!----> <a href="/categories/学习总结/" class="nav-link"><i class="undefined"></i>
  学习总结
</a></li><li class="dropdown-item"><!----> <a href="/categories/踩坑/" class="nav-link"><i class="undefined"></i>
  踩坑
</a></li><li class="dropdown-item"><!----> <a href="/categories/工具/" class="nav-link"><i class="undefined"></i>
  工具
</a></li><li class="dropdown-item"><!----> <a href="/categories/Linux/" class="nav-link"><i class="undefined"></i>
  Linux
</a></li><li class="dropdown-item"><!----> <a href="/categories/算法/" class="nav-link"><i class="undefined"></i>
  算法
</a></li><li class="dropdown-item"><!----> <a href="/categories/Java基础/" class="nav-link"><i class="undefined"></i>
  Java基础
</a></li><li class="dropdown-item"><!----> <a href="/categories/高并发编程/" class="nav-link"><i class="undefined"></i>
  高并发编程
</a></li><li class="dropdown-item"><!----> <a href="/categories/数据库/" class="nav-link"><i class="undefined"></i>
  数据库
</a></li><li class="dropdown-item"><!----> <a href="/categories/Java框架/" class="nav-link"><i class="undefined"></i>
  Java框架
</a></li><li class="dropdown-item"><!----> <a href="/categories/学习笔记/" class="nav-link"><i class="undefined"></i>
  学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/categories/框架学习/" class="nav-link"><i class="undefined"></i>
  框架学习
</a></li><li class="dropdown-item"><!----> <a href="/categories/Java项目/" class="nav-link"><i class="undefined"></i>
  Java项目
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间轴
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-note"></i>
      学习笔记
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/docs/major-notes/java/" class="nav-link"><i class="undefined"></i>
  Java笔记整理
</a></li><li class="dropdown-item"><!----> <a href="/docs/major-notes/juc/" class="nav-link"><i class="undefined"></i>
  JUC学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/docs/more-notes/jvm.html" class="nav-link"><i class="undefined"></i>
  JVM核心知识
</a></li><li class="dropdown-item"><!----> <a href="/docs/more-notes/vue.html" class="nav-link"><i class="undefined"></i>
  Vue入门笔记
</a></li><li class="dropdown-item"><!----> <a href="/docs/major-notes/linux/" class="nav-link"><i class="undefined"></i>
  Linux笔记整理
</a></li><li class="dropdown-item"><!----> <a href="/docs/major-notes/redis/" class="nav-link"><i class="undefined"></i>
  Redis学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/docs/major-notes/springcloud/" class="nav-link"><i class="undefined"></i>
  SpringCloud笔记
</a></li><li class="dropdown-item"><!----> <a href="/docs/major-notes/spring/" class="nav-link"><i class="undefined"></i>
  Spring学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/docs/more-notes/shiro.html" class="nav-link"><i class="undefined"></i>
  Shiro学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/docs/android-notes/" class="nav-link router-link-active"><i class="undefined"></i>
  Android学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/docs/project-notes/" class="nav-link"><i class="undefined"></i>
  项目笔记
</a></li></ul></div></div><div class="nav-item"><a href="/docs/collections/" class="nav-link"><i class="iconfont reco-collection"></i>
  收藏夹
</a></div><div class="nav-item"><a href="/docs/life-logs/" class="nav-link"><i class="iconfont reco-camera"></i>
  生活日志
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-browse"></i>
      常用网站
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="http://www.cxysite.com/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="undefined"></i>
  程序员导航
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://www.nowcoder.com/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="undefined"></i>
  牛客网
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://leetcode-cn.com/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="undefined"></i>
  力扣
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-person"></i>
      私藏博客
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://docker.easydoc.net" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="undefined"></i>
  快速入门docker
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://www.nowcoder.com/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="undefined"></i>
  牛客网
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://leetcode-cn.com/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="undefined"></i>
  力扣
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系方式
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-gitee"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://github.com/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-6f8f7dda></div> <aside class="sidebar" data-v-6f8f7dda><div class="personal-info-wrapper" data-v-cc06b9e8 data-v-6f8f7dda><img src="/avatar.png" alt="author-avatar" class="personal-img" data-v-cc06b9e8> <h3 class="name" data-v-cc06b9e8>
    江流
  </h3> <div class="num" data-v-cc06b9e8><div data-v-cc06b9e8><h3 data-v-cc06b9e8>104</h3> <h6 data-v-cc06b9e8>Articles</h6></div> <div data-v-cc06b9e8><h3 data-v-cc06b9e8>21</h3> <h6 data-v-cc06b9e8>Tags</h6></div></div> <ul class="social-links" data-v-cc06b9e8></ul> <hr data-v-cc06b9e8></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/复盘/" class="nav-link"><i class="undefined"></i>
  复盘
</a></li><li class="dropdown-item"><!----> <a href="/categories/学习总结/" class="nav-link"><i class="undefined"></i>
  学习总结
</a></li><li class="dropdown-item"><!----> <a href="/categories/踩坑/" class="nav-link"><i class="undefined"></i>
  踩坑
</a></li><li class="dropdown-item"><!----> <a href="/categories/工具/" class="nav-link"><i class="undefined"></i>
  工具
</a></li><li class="dropdown-item"><!----> <a href="/categories/Linux/" class="nav-link"><i class="undefined"></i>
  Linux
</a></li><li class="dropdown-item"><!----> <a href="/categories/算法/" class="nav-link"><i class="undefined"></i>
  算法
</a></li><li class="dropdown-item"><!----> <a href="/categories/Java基础/" class="nav-link"><i class="undefined"></i>
  Java基础
</a></li><li class="dropdown-item"><!----> <a href="/categories/高并发编程/" class="nav-link"><i class="undefined"></i>
  高并发编程
</a></li><li class="dropdown-item"><!----> <a href="/categories/数据库/" class="nav-link"><i class="undefined"></i>
  数据库
</a></li><li class="dropdown-item"><!----> <a href="/categories/Java框架/" class="nav-link"><i class="undefined"></i>
  Java框架
</a></li><li class="dropdown-item"><!----> <a href="/categories/学习笔记/" class="nav-link"><i class="undefined"></i>
  学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/categories/框架学习/" class="nav-link"><i class="undefined"></i>
  框架学习
</a></li><li class="dropdown-item"><!----> <a href="/categories/Java项目/" class="nav-link"><i class="undefined"></i>
  Java项目
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间轴
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-note"></i>
      学习笔记
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/docs/major-notes/java/" class="nav-link"><i class="undefined"></i>
  Java笔记整理
</a></li><li class="dropdown-item"><!----> <a href="/docs/major-notes/juc/" class="nav-link"><i class="undefined"></i>
  JUC学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/docs/more-notes/jvm.html" class="nav-link"><i class="undefined"></i>
  JVM核心知识
</a></li><li class="dropdown-item"><!----> <a href="/docs/more-notes/vue.html" class="nav-link"><i class="undefined"></i>
  Vue入门笔记
</a></li><li class="dropdown-item"><!----> <a href="/docs/major-notes/linux/" class="nav-link"><i class="undefined"></i>
  Linux笔记整理
</a></li><li class="dropdown-item"><!----> <a href="/docs/major-notes/redis/" class="nav-link"><i class="undefined"></i>
  Redis学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/docs/major-notes/springcloud/" class="nav-link"><i class="undefined"></i>
  SpringCloud笔记
</a></li><li class="dropdown-item"><!----> <a href="/docs/major-notes/spring/" class="nav-link"><i class="undefined"></i>
  Spring学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/docs/more-notes/shiro.html" class="nav-link"><i class="undefined"></i>
  Shiro学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/docs/android-notes/" class="nav-link router-link-active"><i class="undefined"></i>
  Android学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/docs/project-notes/" class="nav-link"><i class="undefined"></i>
  项目笔记
</a></li></ul></div></div><div class="nav-item"><a href="/docs/collections/" class="nav-link"><i class="iconfont reco-collection"></i>
  收藏夹
</a></div><div class="nav-item"><a href="/docs/life-logs/" class="nav-link"><i class="iconfont reco-camera"></i>
  生活日志
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-browse"></i>
      常用网站
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="http://www.cxysite.com/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="undefined"></i>
  程序员导航
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://www.nowcoder.com/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="undefined"></i>
  牛客网
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://leetcode-cn.com/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="undefined"></i>
  力扣
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-person"></i>
      私藏博客
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://docker.easydoc.net" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="undefined"></i>
  快速入门docker
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://www.nowcoder.com/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="undefined"></i>
  牛客网
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://leetcode-cn.com/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="undefined"></i>
  力扣
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系方式
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-gitee"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://github.com/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav> <ul class="sidebar-links"><li><a href="/docs/android-notes/01-android-.html" class="sidebar-link">Android入门</a></li><li><a href="/docs/android-notes/02-four-contents.html" class="sidebar-link">Android四大组件</a></li><li><a href="/docs/android-notes/03-android-ui.html" class="sidebar-link">Android 界面编程</a></li><li><a href="/docs/android-notes/04-fragment-.html" class="sidebar-link">Fragment</a></li><li><a href="/docs/android-notes/05-file-io.html" class="sidebar-link">Android数据存储与IO</a></li><li><a href="/docs/android-notes/06-jni.html" aria-current="page" class="active sidebar-link">JNI学习笔记</a></li><li><a href="/docs/android-notes/07-aidl.html" class="sidebar-link">AIDL学习笔记</a></li><li><a href="/docs/android-notes/08-evnt-handler.html" class="sidebar-link">Android事件机制</a></li><li><a href="/docs/android-notes/09-signature-mechanism.html" class="sidebar-link">Android 签名机制详解</a></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-f68096de data-v-6f8f7dda><h3 class="title" data-v-f68096de></h3> <!----> <label id="box" class="inputBox" data-v-f68096de><input type="password" value="" data-v-f68096de> <span data-v-f68096de>Konck! Knock!</span> <button data-v-f68096de>OK</button></label> <div class="footer" data-v-f68096de><span data-v-f68096de><i class="iconfont reco-theme" data-v-f68096de></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-f68096de>vuePress-theme-reco</a></span> <span data-v-f68096de><i class="iconfont reco-copyright" data-v-f68096de></i> <a data-v-f68096de><span data-v-f68096de>江流</span>
          
        <span data-v-f68096de>2018 - </span>
        2023
      </a></span></div></div> <div data-v-6f8f7dda><div data-v-6f8f7dda><main class="page"><section style="display:;"><div class="page-title"><h1 class="title">JNI学习笔记</h1> <div data-v-1e62957f><i class="iconfont reco-account" data-v-1e62957f><span data-v-1e62957f>江流</span></i> <!----> <!----> <!----></div></div> <div class="theme-reco-content content__default"><h1 id="jni学习笔记"><a href="#jni学习笔记" class="header-anchor">#</a> JNI学习笔记</h1> <h2 id="jni简介"><a href="#jni简介" class="header-anchor">#</a> JNI简介</h2> <h3 id="jni概述"><a href="#jni概述" class="header-anchor">#</a> JNI概述</h3> <p>JNI 全称 Java Native Interface（Java本地开发接口），是一种协议。通过 JNI 就可以让就 Java 调用 C 语言或者 C++ 代码，并且可以让C 语言调 Java 代码。</p> <p><img src="http://images.xbnote.top/images/202208131603957.png" alt=""></p> <h3 id="jni的作用"><a href="#jni的作用" class="header-anchor">#</a> JNI的作用</h3> <ol><li>通过JNI 技术，可以扩展 Android手机 的功能，如 wifi 热点；</li> <li>native coder执行高效：大量的运算（极品飞车），万能解码（ffmpeg）,Opengl(3D 渲染)；</li> <li>实现代码复用：ffmpeg,onencv(人脸识别库)，7–zip；</li> <li>使用场景：考虑特殊情况</li></ol> <h3 id="jni的使用"><a href="#jni的使用" class="header-anchor">#</a> JNI的使用</h3> <ol><li>熟悉 C 语言</li> <li>熟悉 JNI 开发流程</li></ol> <h2 id="c语言基础"><a href="#c语言基础" class="header-anchor">#</a> C语言基础</h2> <h3 id="helloworld"><a href="#helloworld" class="header-anchor">#</a> HelloWorld</h3> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;stdio.h&gt;</span><span class="token comment">//#include引用标准依赖库</span></span>
<span class="token comment">//stdio: standard input&amp;output 标准的输入输出; stdlib:标准的C语言函数库; .h 头文件的后缀；包含一些函数 </span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;stdlib.h&gt;</span></span>

<span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token comment">//相当于Java的main函数</span>
<span class="token punctuation">{</span>
      <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;Hello world !\n&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//输出函数; \n是回车换行 </span>
      <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;calc&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//调起计算器 </span>
      <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;mspaint&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//调起画版 </span>
      <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;services.msc&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//调起画版 </span>
      <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;java Hello&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//执行字节码 </span>
      <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;pause&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//让docs命令行执行pause命令，作用是控制台停留。 </span>
<span class="token punctuation">}</span> 

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><h3 id="基本数据类型"><a href="#基本数据类型" class="header-anchor">#</a> 基本数据类型</h3> <table><thead><tr><th>数据类型</th> <th>Java语言</th> <th>C语言</th></tr></thead> <tbody><tr><td>byte</td> <td>1byte</td> <td>–</td></tr> <tr><td>short</td> <td>2byte</td> <td>2byte</td></tr> <tr><td>int</td> <td>4byte</td> <td>4byte</td></tr> <tr><td><strong>long</strong></td> <td>8byte</td> <td>4byte</td></tr> <tr><td>float</td> <td>4byte</td> <td>4byte</td></tr> <tr><td>double</td> <td>8byte</td> <td>8byte</td></tr> <tr><td><strong>char</strong></td> <td>2byte</td> <td>1byte</td></tr> <tr><td>boolean</td> <td>1byte</td> <td>1byte</td></tr> <tr><td>signed</td> <td>–</td> <td>4byte</td></tr> <tr><td>unsigned</td> <td>–</td> <td>4byte</td></tr> <tr><td>void</td> <td>–</td> <td>1byte</td></tr></tbody></table> <p>总结：</p> <ol><li>C 语言中 char 类型是1个字节（不可以表示汉字），Java语言是2个字节（可以表示汉字）；</li> <li>C 语言中 long 类型是4个字节，Java 中是 8 个字节;</li> <li>c99标准下，long类型的定义为：不可以比整形小；</li> <li>C语言中 boolean 表示：0（flase）,非0(true)；</li> <li>C语言中没有 byte 类型；</li> <li>unsigned 无符号 0~255；</li> <li>signed 有符号 –128~127；</li> <li>void 无类型，任意类型；</li></ol> <h3 id="输入输出函数"><a href="#输入输出函数" class="header-anchor">#</a> 输入输出函数</h3> <h4 id="占位符"><a href="#占位符" class="header-anchor">#</a> 占位符</h4> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token operator">%</span>d  –  <span class="token keyword">int</span>
<span class="token operator">%</span>ld –  <span class="token keyword">long</span> <span class="token keyword">int</span>
<span class="token operator">%</span>c  –  <span class="token keyword">char</span>
<span class="token operator">%</span>f  –  <span class="token keyword">float</span>
<span class="token operator">%</span>u  –  无符号数
<span class="token operator">%</span>hd –  短整型
<span class="token operator">%</span>lf –  <span class="token keyword">double</span>
<span class="token operator">%</span>x  –  十六进制输出爄nt 或者<span class="token keyword">long</span> <span class="token keyword">int</span> 或者<span class="token keyword">short</span> <span class="token keyword">int</span>
<span class="token operator">%</span>o  –  八进制输出
<span class="token operator">%</span>s  –  字符串
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><h4 id="输入函数"><a href="#输入函数" class="header-anchor">#</a> 输入函数</h4> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdlib.h&gt;</span></span>
<span class="token comment">/**
输入函数 scanf(&quot;占位符&quot;，内地地址) 
*/</span> 

<span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">int</span> i <span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;请输入一个你认为最帅的数字：\n&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token function">scanf</span><span class="token punctuation">(</span><span class="token string">&quot;%d&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;你输入的数字是：%d\n&quot;</span><span class="token punctuation">,</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span> 

    <span class="token comment">//输入 </span>
    <span class="token keyword">char</span> cArray<span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token char">'H'</span><span class="token punctuation">,</span><span class="token char">'E'</span><span class="token punctuation">,</span><span class="token char">'L'</span><span class="token punctuation">,</span><span class="token char">'L'</span><span class="token punctuation">,</span><span class="token char">'O'</span><span class="token punctuation">}</span><span class="token punctuation">;</span> 
    <span class="token comment">//在C语言中没有String 类型，但是可以用char数组来表示 </span>
    <span class="token keyword">int</span> j<span class="token punctuation">;</span>
    <span class="token keyword">for</span><span class="token punctuation">(</span> j<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span>j<span class="token operator">&lt;</span><span class="token number">5</span><span class="token punctuation">;</span>j<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>

        <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;cArray[%d]==%c\n&quot;</span><span class="token punctuation">,</span>j<span class="token punctuation">,</span>cArray<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    

    <span class="token punctuation">}</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;cArray==%s\n&quot;</span><span class="token punctuation">,</span>cArray<span class="token punctuation">)</span><span class="token punctuation">;</span> 

    <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;pause&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br></div></div><h4 id="输出函数"><a href="#输出函数" class="header-anchor">#</a> 输出函数</h4> <div class="language-java line-numbers-mode"><pre class="language-java"><code>#include<span class="token generics"><span class="token punctuation">&lt;</span>stdio<span class="token punctuation">.</span>h<span class="token punctuation">&gt;</span></span>
#include<span class="token generics"><span class="token punctuation">&lt;</span>stdlib<span class="token punctuation">.</span>h<span class="token punctuation">&gt;</span></span>

<span class="token comment">/**
输出函数 printf(&quot;输出的内容对应的占位符&quot;);

在C语言中，默认保留小数点后六位 
要想保留对应的位数，就需要在百分号后边加上“.数字” 
 
十进制：12345678
二进制：1011 1100 0110 0001 0100 1110 
                  110 0001 0100 1110

不同的类型，要用不同的占位去输出，否则精度丢失。 
*/</span> 

<span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
       <span class="token keyword">char</span> c <span class="token operator">=</span> <span class="token char">'A'</span><span class="token punctuation">;</span>
       <span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">12345678</span><span class="token punctuation">;</span>
       <span class="token keyword">long</span> l <span class="token operator">=</span> <span class="token number">123456789</span><span class="token punctuation">;</span>
       <span class="token keyword">float</span> f <span class="token operator">=</span> <span class="token number">3.1415</span><span class="token punctuation">;</span>
       <span class="token keyword">double</span> d <span class="token operator">=</span> <span class="token number">3.1415926535</span><span class="token punctuation">;</span>
       
       <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;c==%c\n&quot;</span><span class="token punctuation">,</span>c<span class="token punctuation">)</span><span class="token punctuation">;</span> 
       <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;i==%d\n&quot;</span><span class="token punctuation">,</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span> 
       <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;l==%ld\n&quot;</span><span class="token punctuation">,</span>l<span class="token punctuation">)</span><span class="token punctuation">;</span> 
       <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;f==%.4f\n&quot;</span><span class="token punctuation">,</span>f<span class="token punctuation">)</span><span class="token punctuation">;</span> 
       <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;d==%.10lf\n&quot;</span><span class="token punctuation">,</span>d<span class="token punctuation">)</span><span class="token punctuation">;</span> 
       <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;i==%hd\n&quot;</span><span class="token punctuation">,</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span> 
       <span class="token comment">//C语言的数组的括号不能写在左边 </span>
       <span class="token keyword">char</span> cArray<span class="token punctuation">[</span><span class="token punctuation">]</span>   <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token char">'A'</span><span class="token punctuation">,</span><span class="token char">'B'</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
       <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;cArray内存地址==%#x\n&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>cArray<span class="token punctuation">)</span><span class="token punctuation">;</span> 
       
       <span class="token keyword">char</span><span class="token operator">*</span> text <span class="token operator">=</span> <span class="token string">&quot;I love you!&quot;</span><span class="token punctuation">;</span>
       <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;text内容==%s\n&quot;</span><span class="token punctuation">,</span>text<span class="token punctuation">)</span><span class="token punctuation">;</span> 
       
       <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;pause&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br></div></div><h3 id="指针"><a href="#指针" class="header-anchor">#</a> 指针</h3> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdlib.h&gt;</span></span>

<span class="token comment">/**
 指针就是内存地址
 内地地址就是指针 
*/</span>

<span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
   <span class="token comment">//定义一个int类型的变量i,并且赋值为10； </span>
   <span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
   <span class="token comment">//定义一个int类型的一级指针变量p </span>
   <span class="token keyword">int</span><span class="token operator">*</span> p<span class="token punctuation">;</span> 
   <span class="token comment">//把i对应的地址赋值给p变量    </span>
   p <span class="token operator">=</span> <span class="token operator">&amp;</span>i<span class="token punctuation">;</span> 
   
   <span class="token comment">//指针取值*p :把p变量对应的地址的值取出来 </span>
   <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;*p===%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span>p<span class="token punctuation">)</span><span class="token punctuation">;</span> 
   <span class="token operator">*</span>p <span class="token operator">=</span> <span class="token number">100</span><span class="token punctuation">;</span><span class="token comment">//赋值 </span>
   <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;*p===%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span>p<span class="token punctuation">)</span><span class="token punctuation">;</span> 
       
  <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;pause&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>     
<span class="token punctuation">}</span>     

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br></div></div><h4 id="两数交换"><a href="#两数交换" class="header-anchor">#</a> 两数交换</h4> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token keyword">void</span> <span class="token function">sitch2</span><span class="token punctuation">(</span><span class="token keyword">int</span><span class="token operator">*</span> a<span class="token punctuation">,</span><span class="token keyword">int</span><span class="token operator">*</span> b<span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token comment">//传地址可以改变值 </span>
   <span class="token keyword">int</span> temp <span class="token operator">=</span> <span class="token operator">*</span>a<span class="token punctuation">;</span>
   <span class="token operator">*</span>a <span class="token operator">=</span> <span class="token operator">*</span>b<span class="token punctuation">;</span>
   <span class="token operator">*</span>b <span class="token operator">=</span> temp<span class="token punctuation">;</span> 
   <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;sitch 中a地址===%#x\n&quot;</span><span class="token punctuation">,</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span> 
   <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;sitch 中b地址===%#x\n&quot;</span><span class="token punctuation">,</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token punctuation">}</span>

<span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
   <span class="token keyword">int</span> a <span class="token operator">=</span> <span class="token number">100</span><span class="token punctuation">;</span>
   <span class="token keyword">int</span> b <span class="token operator">=</span> <span class="token number">200</span><span class="token punctuation">;</span>
   <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;main中a地址===%#x\n&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span> 
   <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;main中b地址===%#x\n&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span> 
   <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;a===%d\n&quot;</span><span class="token punctuation">,</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span> 
   <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;b===%d\n&quot;</span><span class="token punctuation">,</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span> 
   <span class="token function">sitch2</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>a<span class="token punctuation">,</span><span class="token operator">&amp;</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>
   <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;a===%d\n&quot;</span><span class="token punctuation">,</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span> 
   <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;b===%d\n&quot;</span><span class="token punctuation">,</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><h4 id="指针和指针变量"><a href="#指针和指针变量" class="header-anchor">#</a> 指针和指针变量</h4> <ol><li><p>指针就是地址，地址就是指针，地址就是内存单元的编号；</p></li> <li><p>指针变量是存放地址的变量；</p></li> <li><p>指针和指针变量是两个不同的概， 通常我们叙述时会把指针变量简称为指针，实际它们含义并不一样，如：</p> <ul><li><p>指针里存的是100,  指针: 地址--具体</p></li> <li><p>指针里存的是地址, 指针: 指针变量 -- 可变</p></li></ul></li></ol> <h4 id="指针的优点"><a href="#指针的优点" class="header-anchor">#</a> 指针的优点</h4> <p>指针能够直接访问硬件和快速传递数据，能够表示复杂的数据结构，方便处理字符串，指针有助于理解面向对象</p> <h4 id="号的含义"><a href="#号的含义" class="header-anchor">#</a> *号的含义</h4> <ol><li>数学运算符:  3 * 5</li> <li>定义指针变量:  int*  p；</li> <li>指针运算符(取值):  *p (取p的内容(地址)在内存中的值)</li></ol> <h4 id="多级指针"><a href="#多级指针" class="header-anchor">#</a> 多级指针</h4> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdlib.h&gt;</span></span>
<span class="token comment">/**
 多级指针 
 指针指向的是内存地址
 地址就是指针 
*/</span>
<span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
  <span class="token comment">//定义一个int类型的变量i,并且赋值为100； </span>
  <span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">100</span><span class="token punctuation">;</span>  
  <span class="token comment">//定义一个int类型的一级指针变量address1,并且把i的地址赋值给它 </span>
  <span class="token keyword">int</span><span class="token operator">*</span> address1 <span class="token operator">=</span> <span class="token operator">&amp;</span>i<span class="token punctuation">;</span>
  <span class="token comment">//定义一个int类型的二级指针变量 address2，并且把 address1对应的地址赋值给它 </span>
  <span class="token keyword">int</span><span class="token operator">*</span><span class="token operator">*</span> address2 <span class="token operator">=</span> <span class="token operator">&amp;</span>address1<span class="token punctuation">;</span>
  <span class="token comment">//定义三级指针 </span>
  <span class="token keyword">int</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span> address3 <span class="token operator">=</span>  <span class="token operator">&amp;</span>address2<span class="token punctuation">;</span>
  <span class="token comment">//定义四级指针 </span>
 <span class="token comment">// int**** address4 =  &amp;address3;</span>
  
  <span class="token comment">//多级指针取值 ****address4得到的值是100</span>
  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;***address3==%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span>address3<span class="token punctuation">)</span><span class="token punctuation">;</span> 
  <span class="token comment">//*address4</span>
  <span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span>address3 <span class="token operator">=</span> <span class="token number">2000</span><span class="token punctuation">;</span>
  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;***address3==%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span>address3<span class="token punctuation">)</span><span class="token punctuation">;</span> 
       
  <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;pause&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>      
<span class="token punctuation">}</span> 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br></div></div><h3 id="数组"><a href="#数组" class="header-anchor">#</a> 数组</h3> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdlib.h&gt;</span></span>

<span class="token comment">/**
 数组的介绍
 1.数组的取值
 2.数组的取地址
 3.数组是一块连续的内地空间
 4.数组的首元素的首地址和数组的地址相同 
 4.数组的设计
 */</span>
<span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">char</span> cArray<span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token char">'H'</span><span class="token punctuation">,</span><span class="token char">'E'</span><span class="token punctuation">,</span><span class="token char">'L'</span><span class="token punctuation">,</span><span class="token char">'L'</span><span class="token punctuation">,</span><span class="token char">'O'</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token keyword">int</span> iArray<span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">}</span>  <span class="token punctuation">;</span>
    <span class="token comment">//取数组的值</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;cArray[0]==%c\n&quot;</span><span class="token punctuation">,</span>cArray<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;cArray[1]==%c\n&quot;</span><span class="token punctuation">,</span>cArray<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray[0]==%d\n&quot;</span><span class="token punctuation">,</span>iArray<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray[1]==%d\n&quot;</span><span class="token punctuation">,</span>iArray<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">//取内存地址值 </span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;cArray地址==%#x\n&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>cArray<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;cArray[0]地址==%#x\n&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>cArray<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;cArray[1]地址==%#x\n&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>cArray<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;cArray[2]地址==%#x\n&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>cArray<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;cArray地址==%#x\n&quot;</span><span class="token punctuation">,</span>cArray<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;cArray+0地址==%#x\n&quot;</span><span class="token punctuation">,</span>cArray<span class="token operator">+</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;cArray+1地址==%#x\n&quot;</span><span class="token punctuation">,</span> cArray<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;cArray+2地址==%#x\n&quot;</span><span class="token punctuation">,</span> cArray<span class="token operator">+</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray + 0==%#x\n&quot;</span><span class="token punctuation">,</span>iArray<span class="token operator">+</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray + 1==%#x\n&quot;</span><span class="token punctuation">,</span>iArray<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray + 2==%#x\n&quot;</span><span class="token punctuation">,</span>iArray<span class="token operator">+</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray + 3==%#x\n&quot;</span><span class="token punctuation">,</span>iArray<span class="token operator">+</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">//内存是一块连续的内存空间 </span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray地址==%#x\n&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>iArray<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray[0]地址==%#x\n&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>iArray<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray[1]地址==%#x\n&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>iArray<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray[2]地址==%#x\n&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>iArray<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray[3]地址==%#x\n&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>iArray<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">//用指针取值</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray==%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span>iArray<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray[0]==%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span>iArray<span class="token operator">+</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray[1]==%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span>iArray<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray[2]==%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span>iArray<span class="token operator">+</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray[3]==%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span>iArray<span class="token operator">+</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray[0]==%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span><span class="token punctuation">(</span>iArray<span class="token operator">+</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray[1]==%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span><span class="token punctuation">(</span>iArray<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray[2]==%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span><span class="token punctuation">(</span>iArray<span class="token operator">+</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray[3]==%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span><span class="token punctuation">(</span>iArray<span class="token operator">+</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;pause&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br></div></div><h3 id="内存分配"><a href="#内存分配" class="header-anchor">#</a> 内存分配</h3> <h4 id="动态内存和静态内存"><a href="#动态内存和静态内存" class="header-anchor">#</a> 动态内存和静态内存</h4> <p>静态内存是程序编译执行后系统自动分配,由系统自动释放, 静态内存是栈分配的。动态内存是开发者手动分配的, 是堆分配的。</p> <ol><li>从静态存储区域分配。内存在程序编译的时候就已经分配好，这块内存在程序的整个运行期间都存在。例如全局变量，static 变量。</li> <li>在栈上创建。在执行函数时，函数内局部变量的存储单元都可以在栈上创建，函数执行结束时这些存储单元自动被释放。栈内存分配运算内置于处理器的指令集中，效率很高，但是分配的内存容量有限。</li> <li>从堆上分配，亦称动态内存分配。程序在运行的时候用malloc 或new 申请任意多少的内存，程序员自己负责在何时用free 或delete 释放内存。动态内存的生存期由我们决定，使用非常灵活，但问题也最多.</li></ol> <p><strong>堆和栈的区别</strong></p> <ol><li><p>申请方式</p> <ul><li>栈：由系统自动分配.例如,声明一个局部变量int  b; 系统自动在栈中为 b 开辟空间。例如当在调用涵数时，需要保存的变量，最明显的是在递归调用时，要系统自动分配一个栈的空间，后进先出的，而后又由系统释放这个空间。</li> <li>堆：需要程序员自己申请，并指明大小，在 c 中用 malloc 函数，如<code>char* p1 = (char*) malloc(10); //14byte</code>，但是注意p1本身是在栈中的。</li></ul></li> <li><p>申请后系统的响应</p> <ul><li>栈：只要栈的剩余空间大于所申请空间，系统将为程序提供内存，否则将报异常提示栈溢出。</li> <li>堆：首先应该知道操作系统有一个记录空闲内存地址的链表，当系统收到程序的申请时，会遍历该链表，寻找第一个空间大于所申请空间的堆结点，然后将该结点从空闲结点链表中删除，并将该结点的空间分配给程序，另外，对于大多数系统，会在这块内存空间中的首地址处记录本次分配的大小，这样，代码中的 delete 语句才能正确的释放本内存空间。另外，由于找到的堆结点的大小不一定正好等于申请的大小，系统会自动的将多余的那部分重新放入空闲链表中。</li></ul></li> <li><p>申请大小的限制</p> <ul><li>栈：在Windows下,栈是向低地址扩展的数据结构，是一块连续的内存的区域。这句话的意思是栈顶的地址和栈的最大容量是系统预先规定好的，在 Windows下，栈的大小是2M（vc 编译选项中可以设置,其实就是一个STACK参数,缺省2M），如果申请的空间超过栈的剩余空间时，将提示 overflow。因此，能从栈获得的空间较小。</li> <li>堆：堆是向高地址扩展的数据结构，是不连续的内存区域。这是由于系统是用链表来存储的空闲内存地址的，自然是不连续的，而链表的遍历方向是由低地址向高地址。堆的大小受限于计算机系统中有效的虚拟内存。由此可见，堆获得的空间比较灵活，也比较大。</li></ul></li> <li><p>申请效率的比较</p> <ul><li>栈:由系统自动分配，速度较快。但程序员是无法控制的。</li> <li>堆:由 malloc/new 分配的内存，一般速度比较慢，而且容易产生内存碎片,不过用起来最方便.</li></ul></li> <li><p>堆和栈中的存储内容</p> <ul><li>栈:在函数调用时，第一个进栈的是主函数中后的下一条指令（函数调用语句的下一条可执行语句）的地址，然后是函数的各个参数，在大多数的 C 编译器中，参数是由右往左入栈的，然后是函数中的局部变量。注意静态变量是不入栈的。当本次函数调用结束后，局部变量先出栈，然后是参数，最后栈顶指针指向最开始存的地址，也就是主函数中的下一条指令，程序由该点继续运行。</li> <li>堆：一般是在堆的头部用一个字节存放堆的大小。堆中的具体内容有程序员安排。</li></ul></li> <li><p>内存的回收</p> <p>栈上分配的内存，编译器会自动收回；堆上分配的内存，要通过free来显式地收回,否则会造成内存泄漏。</p></li></ol> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdlib.h&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;malloc.h&gt;</span>  <span class="token comment">//不能省略</span></span>
<span class="token comment">//malloc是memory(内存) allocate(分配)的缩写</span>

<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  	<span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span> 					   <span class="token comment">//11行 分配了4个字节 静态分配</span>
    <span class="token comment">/*
       1. 要使用malloc函数，必须添加malloc.h这个头文件
       2. malloc函数只有一个形参，并且形参是整型
       3. 4表示请求系统为本程序分配4个字节
       4. malloc函数只能返回第一个字节的地址
       5. 12行分配了8个字节, p变量占4个字节， p所指向的内存也占4个字节
       6. p本身所占的内存是静态分配的， p所指向的内存是动态分配的    
     */</span>
  	<span class="token keyword">int</span><span class="token operator">*</span> p <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword">int</span> <span class="token operator">*</span><span class="token punctuation">)</span><span class="token function">malloc</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 		<span class="token comment">//12行</span>
     
  	<span class="token operator">*</span>p <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>  <span class="token comment">//*p 表示一个int变量， 只不过*p这个整型变量的内存分配方式和11行的i变量的分配方式不同</span>
  	<span class="token function">free</span><span class="token punctuation">(</span>p<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//freep(p)表示把p所指向的内存给释放掉  </span>
    <span class="token comment">// p本身的内存是静态的，不能由程序员手动释放，p本身的内存只能在p变量所在的函数运行终止时由系统自动释放 </span>
  	<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;大家好！\n&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  	<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><h4 id="静态内存分配"><a href="#静态内存分配" class="header-anchor">#</a> 静态内存分配</h4> <div class="language-java line-numbers-mode"><pre class="language-java"><code>#include<span class="token generics"><span class="token punctuation">&lt;</span>stdio<span class="token punctuation">.</span>h<span class="token punctuation">&gt;</span></span>
#include<span class="token generics"><span class="token punctuation">&lt;</span>stdlib<span class="token punctuation">.</span>h<span class="token punctuation">&gt;</span></span>

<span class="token keyword">void</span> <span class="token function">func</span><span class="token punctuation">(</span><span class="token keyword">int</span><span class="token operator">*</span><span class="token operator">*</span> address<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token comment">//定义int类型的i变量，并且赋值100 </span>
    <span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">100</span><span class="token punctuation">;</span>
    <span class="token comment">// 把i对应的地址赋值给 iPoint变量 </span>
    <span class="token operator">*</span>address <span class="token operator">=</span> <span class="token operator">&amp;</span>i<span class="token punctuation">;</span> 
<span class="token punctuation">}</span>

<span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token comment">//定义int类型的一级指针变量 iPoint</span>
    <span class="token keyword">int</span><span class="token operator">*</span> iPoint<span class="token punctuation">;</span> 
    <span class="token function">func</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>iPoint<span class="token punctuation">)</span><span class="token punctuation">;</span>
    
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;*iPoint===%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span>iPoint<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;*iPoint===%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span>iPoint<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;*iPoint===%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span>iPoint<span class="token punctuation">)</span><span class="token punctuation">;</span>
    
    <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;pause&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   
<span class="token punctuation">}</span>       
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><h4 id="动态内存分配"><a href="#动态内存分配" class="header-anchor">#</a> 动态内存分配</h4> <p>特点：申请完之后，只要不回收就会一直在内存中存在子函数的值，可以被主函数长时间的保留。</p> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdlib.h&gt;</span></span>

<span class="token keyword">void</span> <span class="token function">func</span><span class="token punctuation">(</span><span class="token keyword">int</span><span class="token operator">*</span><span class="token operator">*</span> address<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">100</span><span class="token punctuation">;</span>
    <span class="token keyword">int</span><span class="token operator">*</span> temp<span class="token punctuation">;</span>
    <span class="token comment">//malloc(int)-内存地址 </span>
    temp <span class="token operator">=</span> <span class="token function">malloc</span><span class="token punctuation">(</span><span class="token keyword">sizeof</span><span class="token punctuation">(</span><span class="token keyword">int</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token comment">//把i对应的值，赋值给 temp地址对应的值 </span>
    <span class="token operator">*</span>temp <span class="token operator">=</span> i<span class="token punctuation">;</span>
    <span class="token comment">//把address对应的地址对应的值修改成 temp</span>
    <span class="token operator">*</span>address <span class="token operator">=</span> temp<span class="token punctuation">;</span>
     
    <span class="token function">free</span><span class="token punctuation">(</span>temp<span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token punctuation">}</span>

<span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
      <span class="token comment">//定义int类型的一级指针变量 iPoint</span>
     <span class="token keyword">int</span><span class="token operator">*</span> iPoint<span class="token punctuation">;</span> 
     <span class="token function">func</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>iPoint<span class="token punctuation">)</span><span class="token punctuation">;</span> 
    
     <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;*iPoint===%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span>iPoint<span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;*iPoint===%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span>iPoint<span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;*iPoint===%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span>iPoint<span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;*iPoint===%d\n&quot;</span><span class="token punctuation">,</span><span class="token operator">*</span>iPoint<span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;pause&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br></div></div><h3 id="动态创建数组"><a href="#动态创建数组" class="header-anchor">#</a> 动态创建数组</h3> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdlib.h&gt;</span></span>

<span class="token comment">/**
 动态创建数组 
 输出函数 printf(); 
 输入函数：scanf(&quot;占位符&quot;，内存地址); 
 realloc()重新分配内存 
*/</span>

<span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// 动态数组的创建</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;请输入您要创建数组的长度:\n&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//1、让用户输入一个长度</span>
    <span class="token keyword">int</span> length<span class="token punctuation">;</span>
    <span class="token function">scanf</span><span class="token punctuation">(</span><span class="token string">&quot;%d&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>length<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;您输入数组的长度为:%d\n&quot;</span><span class="token punctuation">,</span>length<span class="token punctuation">)</span><span class="token punctuation">;</span>
    
    <span class="token comment">//2、根据长度，分配内存空间</span>
    <span class="token keyword">int</span><span class="token operator">*</span> iArray <span class="token operator">=</span> <span class="token function">malloc</span><span class="token punctuation">(</span>length<span class="token operator">*</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    
    <span class="token comment">//3、让用户把数组中的元素依次的赋值；</span>
    <span class="token keyword">int</span> i<span class="token punctuation">;</span>
    <span class="token keyword">for</span><span class="token punctuation">(</span>i<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span>i<span class="token operator">&lt;</span>length<span class="token punctuation">;</span>i<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
       <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;请输入iArray[%d]的值：&quot;</span><span class="token punctuation">,</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span>   
       <span class="token function">scanf</span><span class="token punctuation">(</span><span class="token string">&quot;%d&quot;</span><span class="token punctuation">,</span>iArray<span class="token operator">+</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span>                
    <span class="token punctuation">}</span>
    
    <span class="token comment">//4、接收用户输入扩展数组长度</span>
    <span class="token keyword">int</span> suppLength<span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;请输入您要扩展数组的长度:\n&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">scanf</span><span class="token punctuation">(</span><span class="token string">&quot;%d&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>suppLength<span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;您要扩展数组的长度:%d\n&quot;</span><span class="token punctuation">,</span>suppLength<span class="token punctuation">)</span><span class="token punctuation">;</span>
    
    <span class="token comment">//5、根据扩展的长度重新分配空间?</span>
    <span class="token comment">//realloc</span>
    iArray <span class="token operator">=</span> <span class="token function">realloc</span><span class="token punctuation">(</span>iArray<span class="token punctuation">,</span><span class="token punctuation">(</span>length<span class="token operator">+</span>suppLength<span class="token punctuation">)</span><span class="token operator">*</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    
    <span class="token comment">//6、把扩展长度的元素让用户赋值；</span>
    <span class="token keyword">for</span><span class="token punctuation">(</span>i<span class="token operator">=</span>length<span class="token punctuation">;</span>i<span class="token operator">&lt;</span>length<span class="token operator">+</span>suppLength<span class="token punctuation">;</span>i<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
       <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;请输入iArray[%d]的值：&quot;</span><span class="token punctuation">,</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span>   
       <span class="token function">scanf</span><span class="token punctuation">(</span><span class="token string">&quot;%d&quot;</span><span class="token punctuation">,</span>iArray<span class="token operator">+</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span>                
    <span class="token punctuation">}</span>
    
    <span class="token comment">//7、输出数组</span>
    <span class="token keyword">for</span><span class="token punctuation">(</span>i<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span>i<span class="token operator">&lt;</span>length<span class="token operator">+</span>suppLength<span class="token punctuation">;</span>i<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
       <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;iArray[%d]==%d\n&quot;</span><span class="token punctuation">,</span>i<span class="token punctuation">,</span><span class="token operator">*</span><span class="token punctuation">(</span>iArray<span class="token operator">+</span>i<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   

    <span class="token punctuation">}</span>
    
    <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;pause&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br></div></div><h3 id="其他"><a href="#其他" class="header-anchor">#</a> 其他</h3> <h4 id="typedef"><a href="#typedef" class="header-anchor">#</a> Typedef</h4> <p>Typedef 用于声明自定义数据类型，配合各种原有数据类型来达到简化编程的目的的类型定义。可以在类中把名字很长的方法用简写或者代替方式。</p> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;stdio.h&gt;</span> </span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;stdlib.h&gt;</span></span>
<span class="token keyword">typedef</span> <span class="token keyword">int</span> i<span class="token punctuation">;</span>
<span class="token keyword">typedef</span> <span class="token keyword">long</span> l<span class="token punctuation">;</span>
<span class="token keyword">typedef</span> <span class="token keyword">float</span> f<span class="token punctuation">;</span>

<span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    i m <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
    l n <span class="token operator">=</span> <span class="token number">123123123</span><span class="token punctuation">;</span>
    f s <span class="token operator">=</span> <span class="token number">3.1415</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d\n&quot;</span><span class="token punctuation">,</span> m<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%ld\n&quot;</span><span class="token punctuation">,</span> n<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%f\n&quot;</span><span class="token punctuation">,</span> s<span class="token punctuation">)</span><span class="token punctuation">;</span>
    
    <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;pause&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>       
<span class="token punctuation">}</span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><h4 id="结构体"><a href="#结构体" class="header-anchor">#</a> 结构体</h4> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdlib.h&gt;</span></span>

<span class="token comment">//定义结构</span>
<span class="token keyword">struct</span> <span class="token class-name">student</span><span class="token punctuation">{</span>
    <span class="token keyword">int</span> age<span class="token punctuation">;</span><span class="token comment">//4个字节 </span>
    <span class="token keyword">float</span> score<span class="token punctuation">;</span><span class="token comment">//4个字节 </span>
    <span class="token keyword">char</span> sex<span class="token punctuation">;</span>   <span class="token comment">//1个字节 </span>
<span class="token punctuation">}</span><span class="token punctuation">;</span> <span class="token comment">//; 不能省略</span>

<span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token comment">//使用结构图</span>
    <span class="token keyword">struct</span> <span class="token class-name">student</span> stu <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">18</span><span class="token punctuation">,</span><span class="token number">98.9</span><span class="token punctuation">,</span><span class="token char">'W'</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token comment">//结构体取值 </span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;stu.age==%d\n&quot;</span><span class="token punctuation">,</span>stu<span class="token punctuation">.</span>age<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;stu.score==%.1f\n&quot;</span><span class="token punctuation">,</span>stu<span class="token punctuation">.</span>score<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;stu.sex==%c\n&quot;</span><span class="token punctuation">,</span>stu<span class="token punctuation">.</span>sex<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//结构体赋值</span>
    stu<span class="token punctuation">.</span>age <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">;</span>
    stu<span class="token punctuation">.</span>score <span class="token operator">=</span> <span class="token number">100</span><span class="token punctuation">;</span>
    stu<span class="token punctuation">.</span>sex <span class="token operator">=</span> <span class="token char">'M'</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;stu.age==%d\n&quot;</span><span class="token punctuation">,</span>stu<span class="token punctuation">.</span>age<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;stu.score==%.1f\n&quot;</span><span class="token punctuation">,</span>stu<span class="token punctuation">.</span>score<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;stu.sex==%c\n&quot;</span><span class="token punctuation">,</span>stu<span class="token punctuation">.</span>sex<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//结构体的长度 </span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;struct student长度==%d\n&quot;</span><span class="token punctuation">,</span><span class="token keyword">sizeof</span><span class="token punctuation">(</span><span class="token keyword">struct</span> <span class="token class-name">student</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    
    <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;pause&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token punctuation">}</span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br></div></div><h4 id="联合体"><a href="#联合体" class="header-anchor">#</a> 联合体</h4> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdlib.h&gt;</span></span>

<span class="token comment">//定义一个联合体，特点，所有的字段都是使用同一块内存空间； </span>
<span class="token keyword">union</span> Mix <span class="token punctuation">{</span>
     <span class="token keyword">long</span> i<span class="token punctuation">;</span> <span class="token comment">//4个字节 </span>
     <span class="token keyword">int</span> k<span class="token punctuation">;</span> <span class="token comment">//4个字节 </span>
     <span class="token keyword">char</span> ii<span class="token punctuation">;</span><span class="token comment">//1个字节 </span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> 
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;mix:%d\n&quot;</span><span class="token punctuation">,</span><span class="token keyword">sizeof</span><span class="token punctuation">(</span><span class="token keyword">union</span> Mix<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token comment">//实验 </span>
    <span class="token keyword">union</span> Mix m<span class="token punctuation">;</span>
    m<span class="token punctuation">.</span>k <span class="token operator">=</span> <span class="token number">123</span><span class="token punctuation">;</span>
    m<span class="token punctuation">.</span>i <span class="token operator">=</span> <span class="token number">100</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;m.i=%d\n&quot;</span><span class="token punctuation">,</span>m<span class="token punctuation">.</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span>         
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;m.k=%d\n&quot;</span><span class="token punctuation">,</span>m<span class="token punctuation">.</span>k<span class="token punctuation">)</span><span class="token punctuation">;</span>  
    
    <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;pause&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span> 

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br></div></div><h4 id="枚举"><a href="#枚举" class="header-anchor">#</a> 枚举</h4> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdlib.h&gt;</span></span>

<span class="token comment">/**
枚举的值递增 默认首元素的值是0 
*/</span>
<span class="token keyword">enum</span> <span class="token class-name">WeekDay</span> <span class="token punctuation">{</span>
     Monday<span class="token punctuation">,</span>Tuesday<span class="token punctuation">,</span>Wednesday<span class="token punctuation">,</span>Thursday<span class="token punctuation">,</span>Friday<span class="token punctuation">,</span>Saturday<span class="token punctuation">,</span>Sunday
<span class="token punctuation">}</span><span class="token punctuation">;</span>
 
<span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
       <span class="token keyword">enum</span> <span class="token class-name">WeekDay</span> day <span class="token operator">=</span> Wednesday<span class="token punctuation">;</span>
       <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d\n&quot;</span><span class="token punctuation">,</span>day<span class="token punctuation">)</span><span class="token punctuation">;</span>
    
       <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;pause&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h4 id="函数指针"><a href="#函数指针" class="header-anchor">#</a> 函数指针</h4> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdlib.h&gt;</span></span>

<span class="token comment">//定义一个函数 </span>
<span class="token keyword">int</span> <span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">int</span> x<span class="token punctuation">,</span><span class="token keyword">int</span> y<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> x <span class="token operator">+</span> y<span class="token punctuation">;</span>
<span class="token punctuation">}</span> 

<span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
     <span class="token comment">//定义函数指针</span>
     <span class="token keyword">int</span> <span class="token punctuation">(</span><span class="token operator">*</span>android<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token keyword">int</span> x<span class="token punctuation">,</span><span class="token keyword">int</span> y<span class="token punctuation">)</span><span class="token punctuation">;</span> 
     <span class="token comment">//函数指针赋值</span>
     android <span class="token operator">=</span> add<span class="token punctuation">;</span>
     <span class="token comment">//使用函数指针 </span>
     <span class="token keyword">int</span> result <span class="token operator">=</span> <span class="token function">add</span><span class="token punctuation">(</span><span class="token number">99</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;result==%d\n&quot;</span><span class="token punctuation">,</span>result<span class="token punctuation">)</span><span class="token punctuation">;</span>

     <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;pause&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   
<span class="token punctuation">}</span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br></div></div><h4 id="结构体指针"><a href="#结构体指针" class="header-anchor">#</a> 结构体指针</h4> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdlib.h&gt;</span></span>

<span class="token comment">//定义结构</span>
<span class="token keyword">struct</span> <span class="token class-name">student</span><span class="token punctuation">{</span>
    <span class="token keyword">int</span> age<span class="token punctuation">;</span><span class="token comment">//4个字节 </span>
    <span class="token keyword">float</span> score<span class="token punctuation">;</span><span class="token comment">//4个字节 </span>
    <span class="token keyword">char</span> sex<span class="token punctuation">;</span>   <span class="token comment">//1个字节 </span>
<span class="token punctuation">}</span> <span class="token punctuation">;</span>  

<span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token comment">//使用结构图</span>
    <span class="token keyword">struct</span> <span class="token class-name">student</span> stu <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">18</span><span class="token punctuation">,</span><span class="token number">98.9</span><span class="token punctuation">,</span><span class="token char">'W'</span><span class="token punctuation">}</span><span class="token punctuation">;</span>

    <span class="token comment">//结构体指针</span>
    <span class="token keyword">struct</span> <span class="token class-name">student</span><span class="token operator">*</span> point <span class="token operator">=</span> <span class="token operator">&amp;</span>stu<span class="token punctuation">;</span>

    <span class="token keyword">struct</span> <span class="token class-name">student</span><span class="token operator">*</span><span class="token operator">*</span> point2 <span class="token operator">=</span> <span class="token operator">&amp;</span>point<span class="token punctuation">;</span>

    <span class="token comment">//取值运算(*point).age  等价于 point-&gt;age  </span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;(*point).age ==%d\n&quot;</span><span class="token punctuation">,</span><span class="token punctuation">(</span><span class="token operator">*</span>point<span class="token punctuation">)</span><span class="token punctuation">.</span>age <span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;point-&gt;age ==%d\n&quot;</span><span class="token punctuation">,</span>point<span class="token operator">-&gt;</span>age <span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;point-&gt;score ==%f\n&quot;</span><span class="token punctuation">,</span>point<span class="token operator">-&gt;</span>score <span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;point-&gt;sex ==%c\n&quot;</span><span class="token punctuation">,</span>point<span class="token operator">-&gt;</span>sex <span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token comment">//赋值运算</span>
    point<span class="token operator">-&gt;</span>age <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">;</span> 
    point<span class="token operator">-&gt;</span>score <span class="token operator">=</span> <span class="token number">100</span><span class="token punctuation">;</span>
    point<span class="token operator">-&gt;</span>sex <span class="token operator">=</span> <span class="token char">'M'</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;point-&gt;age ==%d\n&quot;</span><span class="token punctuation">,</span>point<span class="token operator">-&gt;</span>age <span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;point-&gt;age ==%d\n&quot;</span><span class="token punctuation">,</span>point<span class="token operator">-&gt;</span>age <span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;point-&gt;score ==%f\n&quot;</span><span class="token punctuation">,</span>point<span class="token operator">-&gt;</span>score <span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;point-&gt;sex ==%c\n&quot;</span><span class="token punctuation">,</span>point<span class="token operator">-&gt;</span>sex <span class="token punctuation">)</span><span class="token punctuation">;</span>  

    <span class="token comment">//二级结构体指针取值 (*point).age  等价于 point-&gt;age   所以  (**point).age 等价于 (*point)-&gt;age</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;(**point2).age ==%d\n&quot;</span><span class="token punctuation">,</span><span class="token punctuation">(</span><span class="token operator">*</span><span class="token operator">*</span>point2<span class="token punctuation">)</span><span class="token punctuation">.</span>age <span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;(*point2)-&gt;age ==%d\n&quot;</span><span class="token punctuation">,</span><span class="token punctuation">(</span><span class="token operator">*</span>point2<span class="token punctuation">)</span><span class="token operator">-&gt;</span>age <span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token comment">//二级指针赋值</span>
    <span class="token punctuation">(</span><span class="token operator">*</span><span class="token operator">*</span>point2<span class="token punctuation">)</span><span class="token punctuation">.</span>age <span class="token operator">=</span> <span class="token number">2000</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;(**point2).age ==%d\n&quot;</span><span class="token punctuation">,</span><span class="token punctuation">(</span><span class="token operator">*</span><span class="token operator">*</span>point2<span class="token punctuation">)</span><span class="token punctuation">.</span>age <span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;(*point2)-&gt;age ==%d\n&quot;</span><span class="token punctuation">,</span><span class="token punctuation">(</span><span class="token operator">*</span>point2<span class="token punctuation">)</span><span class="token operator">-&gt;</span>age <span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token function">system</span><span class="token punctuation">(</span><span class="token string">&quot;pause&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br></div></div><h2 id="jni开发"><a href="#jni开发" class="header-anchor">#</a> JNI开发</h2> <h3 id="ndk集成开发流程"><a href="#ndk集成开发流程" class="header-anchor">#</a> NDK集成开发流程</h3> <p>NDK(native develop kits)：可以实现不同平台下(windows)编译出另一个平台下的可执行二进制文件。</p> <p>配置步骤：</p> <ol><li>下载：<a href="http://dl.google.com/android/ndk/android-ndk-r9-windows-x86_64.zip" target="_blank" rel="noopener noreferrer">Windows 64-bit 版本下载<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>，解压到非中文目录下，配置环境变量</li></ol> <blockquote><p>默认安装目录：\AndroidTools\AndroidSDK\ndk-bundle\</p></blockquote> <ol start="2"><li><p>给AS配置关联NDK</p> <ul><li><p>local.properties中添加配置 <code>ndk.dir=D\:\\AndroidTools\\AndroidSDK\\ndk-bundle</code></p></li> <li><p>gradle.properties中添加配置`android.useDeprecatedNdk=true</p></li></ul></li> <li><p>编写native方法</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">JNIS</span> <span class="token punctuation">{</span>
  	<span class="token keyword">public</span> <span class="token keyword">native</span> <span class="token class-name">String</span> <span class="token function">helloJNI</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div></li> <li><p>定义对应的JNI</p> <ul><li>在main下创建 jni 文件夹</li> <li>生成 native 方法对应的 JNI 函数声明头文件：命令窗口中, 进入 java 文件夹</li></ul> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token comment">#执行命令</span>
javah com.xiaobai.NDKHelloWorld.JNIS
<span class="token comment">#生成头文件</span>
com_xiaobai_NDKHelloWorld_JNIS.h
<span class="token comment">#函数声明</span>
JNIEXPORT jstring JNICALL Java_com_xiaobai_NDKHelloWorld_JNIS_helloJNI<span class="token punctuation">(</span>JNIEnv *, jobject<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><ul><li>将生成的头文件转移到jni文件夹下</li> <li>在 jni下定义对应的函数文件: test.c</li></ul> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&quot;com_xiaobai_NDKHelloWorld_JNIS.h&quot;</span></span>
JNIEXPORT jstring JNICALL <span class="token function">Java_com_xiaobai_NDKHelloWorld_JNIS_helloJNI</span>
    <span class="token punctuation">(</span>JNIEnv <span class="token operator">*</span> env<span class="token punctuation">,</span> jobject jobj<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">NewStringUTF</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span> <span class="token string">&quot;Hello from C&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><ul><li><p>在jni文件夹下创建一个空的C文件: empty.c</p> <blockquote><p>说明: 这是AS的bug, 必须至少2个C文件才能通过编译</p></blockquote></li></ul></li> <li><p>指定编译的不同CPU</p> <div class="language-groovy line-numbers-mode"><pre class="language-groovy"><code>defaultConfig <span class="token punctuation">{</span>
    ndk<span class="token punctuation">{</span>
        moduleName <span class="token interpolation-string"><span class="token string">&quot;HelloJni&quot;</span></span> <span class="token comment">//so文件: lib+moduleName+.so</span>
        abiFilters <span class="token interpolation-string"><span class="token string">&quot;armeabi&quot;</span></span><span class="token punctuation">,</span> <span class="token interpolation-string"><span class="token string">&quot;armeabi-v7a&quot;</span></span><span class="token punctuation">,</span> <span class="token interpolation-string"><span class="token string">&quot;x86&quot;</span></span> <span class="token comment">//cpu的类型</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div></li> <li><p>编译生成不同平台下的动态链接文件</p> <ul><li>执行 rebuild，生成 so 文件</li> <li>so 文件目录：build\intermediates\ndk\debug\lib.....</li></ul></li> <li><p>调用native方法</p> <ul><li>在native方法所在的类中加载 so 文件</li></ul> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">static</span> <span class="token punctuation">{</span>
   <span class="token class-name">System</span><span class="token punctuation">.</span><span class="token function">loadLibrary</span><span class="token punctuation">(</span><span class="token string">&quot;HelloJni&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><ul><li>在Activity中调用 native方法</li></ul> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token class-name">String</span> result <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JNIS</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">helloJNI</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">Log</span><span class="token punctuation">.</span><span class="token function">e</span><span class="token punctuation">(</span><span class="token string">&quot;TAG&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;result=&quot;</span><span class="token operator">+</span>result<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div></li></ol> <blockquote><p>实践过程发现以上配置过程已过时，无法与编译生产ndk目录。新版采用 cmake 方式构建项目，详情参考博客：</p> <p><a href="https://blog.csdn.net/android_cai_niao/article/details/106474705" target="_blank" rel="noopener noreferrer">超详细的Android NDK开发环境搭建<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p></blockquote> <h3 id="详解ndk开发"><a href="#详解ndk开发" class="header-anchor">#</a> 详解NDK开发</h3> <h4 id="开发步骤"><a href="#开发步骤" class="header-anchor">#</a> 开发步骤</h4> <ol><li>进入<code>main</code>目录下执行<code>javah &lt;全类名&gt;</code> 命令生成<code>.h</code>文件；</li> <li>在<code>main</code>目录下添加<code>jni</code>目录，将生成的<code>.h</code>文件移入；</li> <li>创建<code>c</code>文件并引入生成的<code>.h</code>文件，编写<code>JNI</code>实现；</li> <li>添加<code>cMakeList.txt</code>文件</li></ol> <div class="language-tex line-numbers-mode"><pre class="language-tex"><code># 设置构建native library所需的CMake最低版本。
cmake_minimum_required(VERSION 3.4.1)

#创建一个库（多次调用add_library即可创建多个库）
add_library( # 设置库的名称
        libname

        # 将库设置为共享库（即so文件）
        SHARED

        # 指定源文件的相对路径
        source_path )

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><ol start="5"><li>在<code>.gradle</code>文件中添加配置</li></ol> <div class="language-groovy line-numbers-mode"><pre class="language-groovy"><code>android <span class="token punctuation">{</span>
	externalNativeBuild <span class="token punctuation">{</span>
        cmake <span class="token punctuation">{</span>
            path <span class="token function">file</span><span class="token punctuation">(</span><span class="token string">'src/main/jni/CMakeLists.txt'</span><span class="token punctuation">)</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    sourceSets<span class="token punctuation">.</span>main <span class="token punctuation">{</span>
        <span class="token comment">//让AS识别libs下的.so第三方包</span>
        jniLibs<span class="token punctuation">.</span>srcDirs <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">'libs'</span><span class="token punctuation">]</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h4 id="java调用c函数"><a href="#java调用c函数" class="header-anchor">#</a> Java调用C函数</h4> <p>JNI</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">JNIS</span> <span class="token punctuation">{</span>
    <span class="token comment">//两数相加</span>
    <span class="token keyword">public</span> <span class="token keyword">native</span> <span class="token keyword">int</span> <span class="token function">sum</span><span class="token punctuation">(</span><span class="token keyword">int</span> x<span class="token punctuation">,</span> <span class="token keyword">int</span> y<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//字符串拼接</span>
    <span class="token keyword">public</span> <span class="token keyword">native</span> <span class="token class-name">String</span> <span class="token function">sayHello</span><span class="token punctuation">(</span><span class="token class-name">String</span> s<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//数组运算</span>
    <span class="token keyword">public</span> <span class="token keyword">native</span> <span class="token keyword">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token function">incArrElms</span><span class="token punctuation">(</span><span class="token keyword">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span> intArray<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//检查密码</span>
    <span class="token keyword">public</span> <span class="token keyword">native</span> <span class="token keyword">int</span> <span class="token function">checkPwd</span><span class="token punctuation">(</span><span class="token class-name">String</span> pwd<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p>JNI实现</p> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token comment">/**
 * 把一个jstring转换成一个c语言的char* 类型.
 */</span>
<span class="token keyword">char</span><span class="token operator">*</span> <span class="token function">_JString2CStr</span><span class="token punctuation">(</span>JNIEnv<span class="token operator">*</span> env<span class="token punctuation">,</span> jstring jstr<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">char</span><span class="token operator">*</span> rtn <span class="token operator">=</span> <span class="token constant">NULL</span><span class="token punctuation">;</span>
    jclass clsstring <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">FindClass</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span> <span class="token string">&quot;java/lang/String&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    jstring strencode <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">NewStringUTF</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span><span class="token string">&quot;GB2312&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    jmethodID mid <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">GetMethodID</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span> clsstring<span class="token punctuation">,</span> <span class="token string">&quot;getBytes&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;(Ljava/lang/String;)[B&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    jbyteArray barr <span class="token operator">=</span> <span class="token punctuation">(</span>jbyteArray<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">CallObjectMethod</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span> jstr<span class="token punctuation">,</span> mid<span class="token punctuation">,</span> strencode<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// String .getByte(&quot;GB2312&quot;);</span>
    jsize alen <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">GetArrayLength</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span> barr<span class="token punctuation">)</span><span class="token punctuation">;</span>
    jbyte<span class="token operator">*</span> ba <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">GetByteArrayElements</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span> barr<span class="token punctuation">,</span> JNI_FALSE<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span>alen <span class="token operator">&gt;</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        rtn <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword">char</span><span class="token operator">*</span><span class="token punctuation">)</span><span class="token function">malloc</span><span class="token punctuation">(</span>alen<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//&quot;\0&quot;</span>
        <span class="token function">memcpy</span><span class="token punctuation">(</span>rtn<span class="token punctuation">,</span> ba<span class="token punctuation">,</span> alen<span class="token punctuation">)</span><span class="token punctuation">;</span>
        rtn<span class="token punctuation">[</span>alen<span class="token punctuation">]</span><span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">ReleaseByteArrayElements</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span> barr<span class="token punctuation">,</span> ba<span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> rtn<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

JNIEXPORT jint JNICALL <span class="token function">Java_com_xiaobai_javac_JNIS_sum</span><span class="token punctuation">(</span>JNIEnv <span class="token operator">*</span>env<span class="token punctuation">,</span> jobject thiz<span class="token punctuation">,</span> jint x<span class="token punctuation">,</span> jint y<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// TODO: implement sum()</span>
    <span class="token keyword">int</span> result <span class="token operator">=</span> x <span class="token operator">+</span>y<span class="token punctuation">;</span>
    <span class="token keyword">return</span> result<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

JNIEXPORT jstring JNICALL <span class="token function">Java_com_xiaobai_javac_JNIS_sayHello</span><span class="token punctuation">(</span>JNIEnv <span class="token operator">*</span>env<span class="token punctuation">,</span> jobject thiz<span class="token punctuation">,</span> jstring s<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// TODO: implement sayHello()</span>
    <span class="token keyword">char</span><span class="token operator">*</span> fromJava <span class="token operator">=</span> <span class="token function">_JString2CStr</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span>s<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">char</span><span class="token operator">*</span> fromC <span class="token operator">=</span> <span class="token string">&quot;Hello&quot;</span><span class="token punctuation">;</span>
    <span class="token function">strcat</span><span class="token punctuation">(</span>fromJava<span class="token punctuation">,</span>fromC<span class="token punctuation">)</span><span class="token punctuation">;</span>
    jstring result <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">NewStringUTF</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span>fromJava<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> result<span class="token punctuation">;</span>
<span class="token punctuation">}</span>


JNIEXPORT jintArray JNICALL <span class="token function">Java_com_xiaobai_javac_JNIS_incArrElms</span><span class="token punctuation">(</span>JNIEnv <span class="token operator">*</span>env<span class="token punctuation">,</span> jobject thiz<span class="token punctuation">,</span> jintArray int_array<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// TODO: implement incArrElms()</span>
    <span class="token comment">//获取数组长度</span>
    <span class="token keyword">int</span> size <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">GetArrayLength</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span>int_array<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//得到数组元素</span>
    jint<span class="token operator">*</span> arr <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">GetIntArrayElements</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span>int_array<span class="token punctuation">,</span>JNI_FALSE<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//遍历数组</span>
    <span class="token keyword">for</span><span class="token punctuation">(</span><span class="token keyword">int</span> i<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span>i<span class="token operator">&lt;</span>size<span class="token punctuation">;</span>i<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token operator">*</span><span class="token punctuation">(</span>arr<span class="token operator">+</span>i<span class="token punctuation">)</span><span class="token operator">=</span><span class="token operator">*</span><span class="token punctuation">(</span>arr<span class="token operator">+</span>i<span class="token punctuation">)</span><span class="token operator">+</span><span class="token number">10</span><span class="token punctuation">;</span>
        <span class="token operator">*</span><span class="token punctuation">(</span>arr<span class="token operator">+</span>i<span class="token punctuation">)</span><span class="token operator">+=</span><span class="token number">10</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> arr<span class="token punctuation">;</span>
<span class="token punctuation">}</span>


JNIEXPORT jint JNICALL <span class="token function">Java_com_xiaobai_javac_JNIS_checkPwd</span><span class="token punctuation">(</span>JNIEnv <span class="token operator">*</span>env<span class="token punctuation">,</span> jobject thiz<span class="token punctuation">,</span> jstring pwd<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// TODO: implement checkPwd()</span>
    <span class="token keyword">char</span><span class="token operator">*</span> origin <span class="token operator">=</span> <span class="token string">&quot;123456&quot;</span><span class="token punctuation">;</span>
    <span class="token keyword">char</span><span class="token operator">*</span> target <span class="token operator">=</span> <span class="token function">_JString2CStr</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span>pwd<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">int</span> code <span class="token operator">=</span> <span class="token function">strcmp</span><span class="token punctuation">(</span>origin<span class="token punctuation">,</span>target<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>code<span class="token operator">==</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token number">200</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token keyword">else</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token number">400</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br><span class="line-number">59</span><br><span class="line-number">60</span><br><span class="line-number">61</span><br><span class="line-number">62</span><br><span class="line-number">63</span><br></div></div><h4 id="c回调java方法"><a href="#c回调java方法" class="header-anchor">#</a> C回调Java方法</h4> <ol><li><p>C回调Java方法的核心思想: 反射</p></li> <li><p>如何得到一个方法的签名?</p> <ul><li>在命令行窗口中, 进入应用的 javac/debug/ 目录</li> <li>执行命令: javap -s 全类名, 显示所有方法的签名信息</li></ul></li></ol> <p>JNI</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">JNI</span> <span class="token punctuation">{</span>
    <span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span><span class="token function">loadLibrary</span><span class="token punctuation">(</span><span class="token string">&quot;ccalljava&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">/**
     * 当执行这个方法的时候，让C代码调用
     * public int add(int x, int y)
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">native</span> <span class="token keyword">void</span> <span class="token function">callbackAdd</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">/**
     * 当执行这个方法的时候，让C代码调用
     * public void helloFromJava()
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">native</span> <span class="token keyword">void</span> <span class="token function">callbackHelloFromJava</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>


    <span class="token comment">/**
     * 当执行这个方法的时候，让C代码调用void printString(String s)
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">native</span> <span class="token keyword">void</span> <span class="token function">callbackPrintString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">/**
     * 当执行这个方法的时候，让C代码静态方法 static void sayHello(String s)
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">native</span> <span class="token keyword">void</span> <span class="token function">callbackSayHello</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>


    <span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">int</span> x<span class="token punctuation">,</span> <span class="token keyword">int</span> y<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">Log</span><span class="token punctuation">.</span><span class="token function">e</span><span class="token punctuation">(</span><span class="token string">&quot;TAG&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;add() x=&quot;</span> <span class="token operator">+</span> x <span class="token operator">+</span> <span class="token string">&quot; y=&quot;</span> <span class="token operator">+</span> y<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> x <span class="token operator">+</span> y<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">helloFromJava</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">Log</span><span class="token punctuation">.</span><span class="token function">e</span><span class="token punctuation">(</span><span class="token string">&quot;TAG&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;helloFromJava()&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">printString</span><span class="token punctuation">(</span><span class="token class-name">String</span> s<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">Log</span><span class="token punctuation">.</span><span class="token function">e</span><span class="token punctuation">(</span><span class="token string">&quot;TAG&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;C中输入的：&quot;</span> <span class="token operator">+</span> s<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">sayHello</span><span class="token punctuation">(</span><span class="token class-name">String</span> s<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">Log</span><span class="token punctuation">.</span><span class="token function">e</span><span class="token punctuation">(</span><span class="token string">&quot;TAG&quot;</span><span class="token punctuation">,</span>  <span class="token string">&quot;我是java代码中的JNI.&quot;</span>
                <span class="token operator">+</span> <span class="token string">&quot;java中的sayHello(String s)静态方法，我被C调用了:&quot;</span><span class="token operator">+</span> s<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br></div></div><p>MainActivity</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">MainActivity</span> <span class="token keyword">extends</span> <span class="token class-name">AppCompatActivity</span> <span class="token punctuation">{</span>

    <span class="token keyword">private</span> <span class="token class-name">JNI</span> jni<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">protected</span> <span class="token keyword">void</span> <span class="token function">onCreate</span><span class="token punctuation">(</span><span class="token class-name">Bundle</span> savedInstanceState<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">onCreate</span><span class="token punctuation">(</span>savedInstanceState<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token function">setContentView</span><span class="token punctuation">(</span><span class="token class-name">R</span><span class="token punctuation">.</span>layout<span class="token punctuation">.</span>activity_main<span class="token punctuation">)</span><span class="token punctuation">;</span>
        jni <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JNI</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">//显示Toast</span>
    <span class="token keyword">public</span> <span class="token keyword">native</span> <span class="token keyword">void</span> <span class="token function">callbackShowToast</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">showToast</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">Log</span><span class="token punctuation">.</span><span class="token function">e</span><span class="token punctuation">(</span><span class="token string">&quot;Tag&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;showToast&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">Toast</span><span class="token punctuation">.</span><span class="token function">makeText</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">,</span><span class="token string">&quot;result==ok&quot;</span><span class="token punctuation">,</span><span class="token class-name">Toast</span><span class="token punctuation">.</span><span class="token constant">LENGTH_SHORT</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">show</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br></div></div><p>JNI实现</p> <div class="language-c line-numbers-mode"><pre class="language-c"><code>
<span class="token comment">/**
 * 把一个jstring转换成一个c语言的char* 类型.
 */</span>
<span class="token keyword">char</span><span class="token operator">*</span> <span class="token function">_JString2CStr</span><span class="token punctuation">(</span>JNIEnv<span class="token operator">*</span> env<span class="token punctuation">,</span> jstring jstr<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">char</span><span class="token operator">*</span> rtn <span class="token operator">=</span> <span class="token constant">NULL</span><span class="token punctuation">;</span>
    jclass clsstring <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">FindClass</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span> <span class="token string">&quot;java/lang/String&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    jstring strencode <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">NewStringUTF</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span><span class="token string">&quot;GB2312&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    jmethodID mid <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">GetMethodID</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span> clsstring<span class="token punctuation">,</span> <span class="token string">&quot;getBytes&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;(Ljava/lang/String;)[B&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    jbyteArray barr <span class="token operator">=</span> <span class="token punctuation">(</span>jbyteArray<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">CallObjectMethod</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span> jstr<span class="token punctuation">,</span> mid<span class="token punctuation">,</span> strencode<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// String .getByte(&quot;GB2312&quot;);</span>
    jsize alen <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">GetArrayLength</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span> barr<span class="token punctuation">)</span><span class="token punctuation">;</span>
    jbyte<span class="token operator">*</span> ba <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">GetByteArrayElements</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span> barr<span class="token punctuation">,</span> JNI_FALSE<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span>alen <span class="token operator">&gt;</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        rtn <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword">char</span><span class="token operator">*</span><span class="token punctuation">)</span><span class="token function">malloc</span><span class="token punctuation">(</span>alen<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//&quot;\0&quot;</span>
        <span class="token function">memcpy</span><span class="token punctuation">(</span>rtn<span class="token punctuation">,</span> ba<span class="token punctuation">,</span> alen<span class="token punctuation">)</span><span class="token punctuation">;</span>
        rtn<span class="token punctuation">[</span>alen<span class="token punctuation">]</span><span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">ReleaseByteArrayElements</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span> barr<span class="token punctuation">,</span> ba<span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> rtn<span class="token punctuation">;</span>
<span class="token punctuation">}</span>


JNIEXPORT <span class="token keyword">void</span> JNICALL
<span class="token function">Java_com_xiaobai_cjava_JNI_callbackAdd</span><span class="token punctuation">(</span>JNIEnv <span class="token operator">*</span>env<span class="token punctuation">,</span> jobject thiz<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">//得到字节码</span>
    jclass jclazz <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">FindClass</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span><span class="token string">&quot;com/xiaobai/cjava/JNI&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//获取调用方法签名</span>
    jmethodID  jmethodId <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">GetMethodID</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span>jclazz<span class="token punctuation">,</span><span class="token string">&quot;add&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;(II)I&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//获取Java实例</span>
    jobject jobject <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">AllocObject</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span>jclazz<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//调用方法</span>
    <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">CallIntMethod</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span>jobject<span class="token punctuation">,</span> jmethodId<span class="token punctuation">,</span><span class="token number">100</span><span class="token punctuation">,</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

JNIEXPORT <span class="token keyword">void</span> JNICALL
<span class="token function">Java_com_xiaobai_cjava_JNI_callbackHelloFromJava</span><span class="token punctuation">(</span>JNIEnv <span class="token operator">*</span>env<span class="token punctuation">,</span> jobject thiz<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// 获取字节码</span>
    jclass jclazz <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">FindClass</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span><span class="token string">&quot;com/xiaobai/cjava/JNI&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//获取调用方法签名</span>
    jmethodID  jmethodId <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">GetMethodID</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span>jclazz<span class="token punctuation">,</span><span class="token string">&quot;helloFromJava&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;()V&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//获取Java实例</span>
    jobject jobject <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">AllocObject</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span>jclazz<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//调用方法</span>
    <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">CallVoidMethod</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span>jobject<span class="token punctuation">,</span>jmethodId<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

JNIEXPORT <span class="token keyword">void</span> JNICALL
<span class="token function">Java_com_xiaobai_cjava_JNI_callbackPrintString</span><span class="token punctuation">(</span>JNIEnv <span class="token operator">*</span>env<span class="token punctuation">,</span> jobject thiz<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// 获取字节码</span>
    jclass jclazz <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">FindClass</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span><span class="token string">&quot;com/xiaobai/cjava/JNI&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//获取调用方法签名</span>
    jmethodID  jmethodId <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">GetMethodID</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span>jclazz<span class="token punctuation">,</span><span class="token string">&quot;printString&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;(Ljava/lang/String;)V&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//获取Java实例</span>
    jobject jobject <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">AllocObject</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span>jclazz<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//调用方法</span>
    jstring jstring <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">NewStringUTF</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span><span class="token string">&quot;I am from c&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">CallVoidMethod</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span>jobject<span class="token punctuation">,</span>jmethodId<span class="token punctuation">,</span>jstring<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

JNIEXPORT <span class="token keyword">void</span> JNICALL
<span class="token function">Java_com_xiaobai_cjava_JNI_callbackSayHello</span><span class="token punctuation">(</span>JNIEnv <span class="token operator">*</span>env<span class="token punctuation">,</span> jobject thiz<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// 获取字节码</span>
    jclass jclazz <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">FindClass</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span><span class="token string">&quot;com/xiaobai/cjava/JNI&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//获取调用方法签名</span>
    jmethodID  jmethodId <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">GetStaticMethodID</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span>jclazz<span class="token punctuation">,</span><span class="token string">&quot;sayHello&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;(Ljava/lang/String;)V&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//调用方法</span>
    jstring jstring <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">NewStringUTF</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span><span class="token string">&quot;I am from android c&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">CallStaticVoidMethod</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span>jclazz<span class="token punctuation">,</span>jmethodId<span class="token punctuation">,</span>jstring<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>


JNIEXPORT <span class="token keyword">void</span> JNICALL
<span class="token function">Java_com_xiaobai_cjava_MainActivity_callbackShowToast</span><span class="token punctuation">(</span>JNIEnv <span class="token operator">*</span>env<span class="token punctuation">,</span> jobject thiz<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// 获取字节码</span>
    jclass jclazz <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">FindClass</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span><span class="token string">&quot;com/xiaobai/cjava/MainActivity&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//获取调用方法签名</span>
    jmethodID  jmethodId <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">GetMethodID</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span>jclazz<span class="token punctuation">,</span><span class="token string">&quot;showToast&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;()V&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//调用方法</span>
    <span class="token punctuation">(</span><span class="token operator">*</span>env<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">CallVoidMethod</span><span class="token punctuation">(</span>env<span class="token punctuation">,</span>thiz<span class="token punctuation">,</span>jmethodId<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br><span class="line-number">59</span><br><span class="line-number">60</span><br><span class="line-number">61</span><br><span class="line-number">62</span><br><span class="line-number">63</span><br><span class="line-number">64</span><br><span class="line-number">65</span><br><span class="line-number">66</span><br><span class="line-number">67</span><br><span class="line-number">68</span><br><span class="line-number">69</span><br><span class="line-number">70</span><br><span class="line-number">71</span><br><span class="line-number">72</span><br><span class="line-number">73</span><br><span class="line-number">74</span><br><span class="line-number">75</span><br><span class="line-number">76</span><br><span class="line-number">77</span><br><span class="line-number">78</span><br><span class="line-number">79</span><br><span class="line-number">80</span><br></div></div><h4 id="jni打印日志"><a href="#jni打印日志" class="header-anchor">#</a> JNI打印日志</h4> <ol><li>在 CMakeLists.txt 文件中引用添加原生 NDK Log 包；</li></ol> <div class="language-tex line-numbers-mode"><pre class="language-tex"><code>find_library( # Defines the name of the path variable that stores the
        # location of the NDK library.
        log

        # Specifies the name of the NDK library that
        # CMake needs to locate.
        log )
target_link_libraries( # Specifies the target library.
        jni-lib

        # Links the log library to the target library.
        $<span class="token punctuation">{</span>log<span class="token punctuation">}</span> )
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><ol start="2"><li>JNI 实现文件引用</li></ol> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;android/log.h&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">define</span> <span class="token macro-name">LOG_TAG</span> <span class="token string">&quot;jni-name&quot;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">define</span> <span class="token macro-name function">LOGI</span><span class="token expression"><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span>  <span class="token function">__android_log_print</span><span class="token punctuation">(</span>ANDROID_LOG_DEBUG<span class="token punctuation">,</span>LOG_TAG<span class="token punctuation">,</span>__VA_ARGS__<span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">define</span> <span class="token macro-name function">LOGI</span><span class="token expression"><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span>  <span class="token function">__android_log_print</span><span class="token punctuation">(</span>ANDROID_LOG_INFO<span class="token punctuation">,</span>LOG_TAG<span class="token punctuation">,</span>__VA_ARGS__<span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">define</span> <span class="token macro-name function">LOGE</span><span class="token expression"><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span>  <span class="token function">__android_log_print</span><span class="token punctuation">(</span>ANDROID_LOG_ERROR<span class="token punctuation">,</span>LOG_TAG<span class="token punctuation">,</span>__VA_ARGS__<span class="token punctuation">)</span></span></span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p>更多详情内容，请参考：<a href="https://developer.android.google.cn/ndk" target="_blank" rel="noopener noreferrer">NDK开发者文档<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <p>其他参考博客：<a href="https://blog.csdn.net/Xiaoma_Pedro/article/details/112297685" target="_blank" rel="noopener noreferrer">Android系统的JNI原理分析（五）- JNI函数解析<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p></div></section> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">最近更新时间: </span> <span class="time">5/6/2023, 6:41:13 PM</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev"><a href="/docs/android-notes/05-file-io.html" class="prev">
          Android数据存储与IO
        </a></span> <span class="next"><a href="/docs/android-notes/07-aidl.html">
          AIDL学习笔记
        </a></span></p></div> <div class="comments-wrapper"><!----></div></main></div> <!----></div> <ul class="sub-sidebar sub-sidebar-wrapper" style="width:12rem;" data-v-6986a797 data-v-6f8f7dda><li class="level-2" data-v-6986a797><a href="/docs/android-notes/06-jni.html#jni简介" class="sidebar-link reco-side-jni简介" data-v-6986a797>JNI简介</a></li><li class="level-3" data-v-6986a797><a href="/docs/android-notes/06-jni.html#jni概述" class="sidebar-link reco-side-jni概述" data-v-6986a797>JNI概述</a></li><li class="level-3" data-v-6986a797><a href="/docs/android-notes/06-jni.html#jni的作用" class="sidebar-link reco-side-jni的作用" data-v-6986a797>JNI的作用</a></li><li class="level-3" data-v-6986a797><a href="/docs/android-notes/06-jni.html#jni的使用" class="sidebar-link reco-side-jni的使用" data-v-6986a797>JNI的使用</a></li><li class="level-2" data-v-6986a797><a href="/docs/android-notes/06-jni.html#c语言基础" class="sidebar-link reco-side-c语言基础" data-v-6986a797>C语言基础</a></li><li class="level-3" data-v-6986a797><a href="/docs/android-notes/06-jni.html#helloworld" class="sidebar-link reco-side-helloworld" data-v-6986a797>HelloWorld</a></li><li class="level-3" data-v-6986a797><a href="/docs/android-notes/06-jni.html#基本数据类型" class="sidebar-link reco-side-基本数据类型" data-v-6986a797>基本数据类型</a></li><li class="level-3" data-v-6986a797><a href="/docs/android-notes/06-jni.html#输入输出函数" class="sidebar-link reco-side-输入输出函数" data-v-6986a797>输入输出函数</a></li><li class="level-3" data-v-6986a797><a href="/docs/android-notes/06-jni.html#指针" class="sidebar-link reco-side-指针" data-v-6986a797>指针</a></li><li class="level-3" data-v-6986a797><a href="/docs/android-notes/06-jni.html#数组" class="sidebar-link reco-side-数组" data-v-6986a797>数组</a></li><li class="level-3" data-v-6986a797><a href="/docs/android-notes/06-jni.html#内存分配" class="sidebar-link reco-side-内存分配" data-v-6986a797>内存分配</a></li><li class="level-3" data-v-6986a797><a href="/docs/android-notes/06-jni.html#动态创建数组" class="sidebar-link reco-side-动态创建数组" data-v-6986a797>动态创建数组</a></li><li class="level-3" data-v-6986a797><a href="/docs/android-notes/06-jni.html#其他" class="sidebar-link reco-side-其他" data-v-6986a797>其他</a></li><li class="level-2" data-v-6986a797><a href="/docs/android-notes/06-jni.html#jni开发" class="sidebar-link reco-side-jni开发" data-v-6986a797>JNI开发</a></li><li class="level-3" data-v-6986a797><a href="/docs/android-notes/06-jni.html#ndk集成开发流程" class="sidebar-link reco-side-ndk集成开发流程" data-v-6986a797>NDK集成开发流程</a></li><li class="level-3" data-v-6986a797><a href="/docs/android-notes/06-jni.html#详解ndk开发" class="sidebar-link reco-side-详解ndk开发" data-v-6986a797>详解NDK开发</a></li></ul></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div></div></div>
    <script src="/assets/js/app.371ed010.js" defer></script><script src="/assets/js/3.fe7e7b6d.js" defer></script><script src="/assets/js/1.adb5634c.js" defer></script><script src="/assets/js/36.470d3b70.js" defer></script>
  </body>
</html>
